package cn.csc.module.pay.mq.producer;

import cn.csc.module.pay.message.JzbOrderMessage;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageConst;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 发送见证宝订单消息(事务消息)
 * @author liuchuang
 * @version 1.0
 * @modify
 * @since 2024/11/22 11:12
 */
@Slf4j
@Component
public class JzbOrderProducer {

    @Resource
    private StreamBridge streamBridge;

    /**
     * 发送 {@link JzbOrderMessage} 消息
     * @param orderMessage orderMessage
     * @return
     */
    public Boolean sendJzbOrderMessage(JzbOrderMessage orderMessage) {

        Message<JzbOrderMessage> message = MessageBuilder.withPayload(orderMessage)
                // 设置ORIGIN_MESSAGE_ID
                .setHeader(MessageConst.PROPERTY_ORIGIN_MESSAGE_ID, orderMessage.getId())
                .setHeader(MessageConst.PROPERTY_TAGS, "jzbOrderTag")
                .build();
        return streamBridge.send("jzbOrder-out-0", message);
    }


}
